package com.example.springaop.Aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
//@Component
public class AspectDemo1 {
    @Around("execution(* com.example.springaop.Controller.*.*(..))")
    public Object recordTime(ProceedingJoinPoint pjp){
        log.info("目标方法执行前...");
        Object result = null;
        try{
            result=pjp.proceed();
        }catch (Throwable e){
            log.error("目标方法出错...");
        }
        log.info("目标方法执行后...");
        return result;
    }
    @Before("execution(* com.example.springaop.Controller.*.*(..))")
    public void before(){
        log.info("before...");
    }
    @After("execution(* com.example.springaop.Controller.*.*(..))")
    public void after(){
        log.info("after...");
    }
    @AfterReturning("execution(* com.example.springaop.Controller.*.*(..))")
    public void afterReturning(){
        log.info("afterReturning...");
    }
    @AfterThrowing("execution(* com.example.springaop.Controller.*.*(..))")
    public void afterThrowing(){
        log.info("afterThrowing...");
    }
}
